package com.migo.api;


import com.migo.annotation.IgnoreAuth;
import com.migo.defence.RtCode;
import com.migo.entity.MgMarketingBannerEntity;
import com.migo.entity.PvMgFirmwareEntity;
import com.migo.entity.PvMgFirmwareVerisonEntity;
import com.migo.enums.BusinessType;
import com.migo.service.PvMgFirmwareService;
import com.migo.service.PvMgFirmwareVerisonService;
import com.migo.utils.AddressUtils;
import com.migo.utils.JsonUtils;
import com.migo.utils.MGUtils;
import com.migo.utils.R;
import com.migo.utils.redis.RedisCacheUtil;
import com.migo.validator.Assert;
import com.migo.view.MgFirmwareView;
import com.migo.view.MgItemFirmwareView;
import lombok.extern.java.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

/**
 * API登录授权
 *
 * @author 知秋
 * @email fei6751803@163.com
 */
@RestController
@RequestMapping("/api/mg")
public class ApiMgFirmwareController {
    private static final Logger log = LoggerFactory.getLogger(ApiMgFirmwareController.class);

    @Autowired
    private PvMgFirmwareVerisonService pvMgFirmwareVerisonService;

    @Autowired
    private PvMgFirmwareService pvMgFirmwareService;

    @Autowired
    private RedisCacheUtil<List<PvMgFirmwareEntity>> pvMgFirmwareRedisCacheUtil;

    @Autowired
    private RedisCacheUtil<PvMgFirmwareEntity> pvMgFirmwareLastRedisCacheUtil;

    @Autowired
    private RedisCacheUtil<List<PvMgFirmwareVerisonEntity>> pvMgFirmwareVersionRedisCacheUtil;

    @Autowired
    private RedisCacheUtil<PvMgFirmwareVerisonEntity> pvMgFirmwareVersionLastRedisCacheUtil;

    @Autowired
    public RedisTemplate redisTemplate;

    @Value("${ossUrl}")
    String ossUrl;

    private Integer isUpdateFlag = 0;  // 1-需要更新 0-检查没有需要更新的
    /**
     * 查询匹配最新固件，先通过app版本查支持的大版本，然后通过大版本号查找需要更新的固件包，如果大版本为空，通过bt、pd和gm版本查找大版本，如果这些条件都查不到大版本就返回当前app版本支持的最新固件
     */
    @IgnoreAuth
    @RequestMapping(value = "/queryFirmware", produces = "application/json;charset=utf-8;")
    public R queryFirmware(@RequestParam Map<String, String> params) {
        String gm_version = "0.0.0";
        String pd_version = "0.0.0";
        String bt_version = "0.0.0";
        String pdrs_version="";
        String bttlw_version="";
        String gmgm_version="";
        String app_version = params.get("app_version");
        String big_version = params.get("big_version");
        String flushFlag="noFlush";
        if(params.containsKey("flush")){
            flushFlag = "flush";
        }
        if(params.containsKey("pd_version")){
            pd_version = params.get("pd_version");
        }
        if(params.containsKey("bt_version")){
            bt_version = params.get("bt_version");
        }
        if(params.containsKey("pdrs_version")){
            pdrs_version = params.get("pdrs_version");
        }
        if(params.containsKey("bttlw_version")){
            bttlw_version = params.get("bttlw_version");
        }
        if(params.containsKey("gmgm_version")){
            gmgm_version = params.get("gmgm_version");
        }
        if(params.containsKey("gm_version")){
            gm_version = params.get("gm_version");
        }
        if(app_version.contains("国际化")){
            app_version = "1.1.3";
        }

        //要加参数：app 版本，大版本号
        /**
         * 首先匹配APP版本，  3.0  数据表里边  匹配范围是否存在
         */
        String boot_runner_version = params.get("boot_runner_version");

        try {

            MgFirmwareView view = new MgFirmwareView();
            /**
             *  先按大版本号查出对应的固件版本信息（应该的配置）
             */
            PvMgFirmwareVerisonEntity lastVersion =  new PvMgFirmwareVerisonEntity();
            //先按app版本匹配最新的固件版本信息，如果空，查状态为0的最新的固件版本配置信息
            if (!"".equals(app_version) && app_version != null) {  //boorRunner 有值获取最新的数据
                String key = "queryMatchBigVision:" + "app_version:"  + app_version;
                if (pvMgFirmwareVersionLastRedisCacheUtil.hashKey(key)) {
                    lastVersion =  pvMgFirmwareVersionLastRedisCacheUtil.getCacheObject(key);
                    if (params.containsKey("flush")) {  //刷新标志
                        pvMgFirmwareVersionLastRedisCacheUtil.deleteObject(key);
                    }
                }else {
                    //查询数据库写入redis
                    synchronized (this) {
                        lastVersion = pvMgFirmwareVerisonService.queryMatchBigVision(app_version);
                        pvMgFirmwareVersionLastRedisCacheUtil.setCacheObject(key, lastVersion);
                    }
                }
            }else {
               // 查状态为0的最新的固件版本配置信息
            }

            PvMgFirmwareVerisonEntity currentVerisonEntity = new PvMgFirmwareVerisonEntity();
            /*if (!"".equals(big_version)) {  //boorRunner 有值获取最新的数据
                String key = "queryByBigVersion:" + "big_version:"  + big_version;
                if (pvMgFirmwareVersionLastRedisCacheUtil.hashKey(key)) {
                    lastVersion =  pvMgFirmwareVersionLastRedisCacheUtil.getCacheObject(key);
                    if (params.containsKey("flush")) {  //刷新标志
                        pvMgFirmwareVersionLastRedisCacheUtil.deleteObject(key);
                    }
                } else {
                    //查询数据库写入redis
                    synchronized (this) {
                        lastVersion = pvMgFirmwareVerisonService.queryByBigVersion(big_version);
                        pvMgFirmwareVersionLastRedisCacheUtil.setCacheObject(key, lastVersion);
                    }
                }

            }else {

                //大版本号为空，需要通过 固件版本查找，不能为空
                if(!"".equals(gm_version) && gm_version!=null && !"".equals(pd_version) && pd_version!=null  && !"".equals(bt_version) && bt_version!=null ){
                    lastVersion = pvMgFirmwareVerisonService.queryLastVersion(gm_version,pd_version,bt_version,pdrs_version);
                }

            }*/
            if(null==lastVersion){
                return R.error(RtCode.ServerError.getCode(), "没有匹配到此app版本信息，请检查app版本号");
            }else{
                if(params.containsKey("gm_version")) {
                    currentVerisonEntity.setGmVersion(gm_version);
                    currentVerisonEntity.setGmgmVersion("");
                }else{
                    currentVerisonEntity.setGmVersion(gm_version);
                    currentVerisonEntity.setPdVersion(pd_version);
                    currentVerisonEntity.setBtVersion(bt_version);
                }
                if(params.containsKey("bt_version")) {
                    currentVerisonEntity.setBtVersion(bt_version);
                    currentVerisonEntity.setBttlwVersion("");
                }
                if(params.containsKey("pd_version")) {
                    currentVerisonEntity.setPdVersion(pd_version);
                    //pd  pdrs huchi
                    currentVerisonEntity.setPdrsVersion("");
                }else {
                    currentVerisonEntity.setPdrsVersion(pdrs_version);
                }
                if(params.containsKey("pdrs_version")) {
                    currentVerisonEntity.setPdrsVersion(pdrs_version);
                    currentVerisonEntity.setPdVersion("");
                }
                if(params.containsKey("bttlw_version")) {
                    currentVerisonEntity.setBttlwVersion(bttlw_version);
                    currentVerisonEntity.setBtVersion("");
                }
                if(params.containsKey("gmgm_version")) {
                    currentVerisonEntity.setGmgmVersion(gmgm_version);
                    currentVerisonEntity.setGmVersion("");
                }
                view = getMgFirmwareView(currentVerisonEntity, lastVersion, big_version,flushFlag);
               // view.setIsUpdate(isUpdateFlag);
            }

            return R.ok().put("data", view);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(RtCode.ServerError.getCode(), RtCode.ServerError.getMsg());
        }
    }

    public PvMgFirmwareEntity getMgFirmwareByType(String firmwareType,String firmwareVersion,String flushFlag){
        PvMgFirmwareEntity pvMgFirmwareEntity = null;
        String key = "queryFirmwareVersionByType:" + "Type:"+firmwareType+":"+firmwareVersion;
        if (pvMgFirmwareVersionLastRedisCacheUtil.hashKey(key)) {
            pvMgFirmwareEntity =  pvMgFirmwareVersionLastRedisCacheUtil.getCacheObject(key);
            if (("flush").equals(flushFlag)) {  //刷新标志
                pvMgFirmwareVersionLastRedisCacheUtil.deleteObject(key);
            }
        }else {
            //查询数据库写入redis
            synchronized (this) {
                Map<String, Object> childMap = new HashMap<>();
                childMap.put("version", firmwareVersion);
                childMap.put("type", firmwareType);
                pvMgFirmwareEntity = pvMgFirmwareService.queryFirmwareVersionByType(childMap);
                pvMgFirmwareVersionLastRedisCacheUtil.setCacheObject(key, pvMgFirmwareEntity);
            }
        }
        return pvMgFirmwareEntity;
    }

    /**
     * 查询固件及子固件相关数据
     *
     * @param currentVerisonEntity
     *  @return
     */
    public MgFirmwareView getMgFirmwareView(PvMgFirmwareVerisonEntity currentVerisonEntity, PvMgFirmwareVerisonEntity lastVersion,String big_version,String flushFlag) {

        /**
         *   实际的配置
         *  1、根据app版本查詢 匹配的大版本
         *  2、检查是否和當前的版本号匹配
         *  3、返回匹配的固件信息和是否需要强制升级字段
         *  4、如果强制升级mustupdate和isUpdate都是1，如果只是需要升级，不需要强制，mustupdate是0，isUpdate是1
         */

        MgFirmwareView view = new MgFirmwareView();
        BeanUtils.copyProperties(lastVersion, view);
        //云台固件- GM固件
        if (!"".equals(currentVerisonEntity.getGmVersion()) && currentVerisonEntity.getGmVersion() != null) {

            if (!"".equals(lastVersion.getGmVersion()) && lastVersion.getGmVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("GM", lastVersion.getGmVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("GM", currentVerisonEntity.getGmVersion(), flushFlag);
                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (lastFirmwareEntity == null) {
                    lastFirmwareEntity.setIsUpdate(0);
                    isUpdateFlag = 0;
                } else {

                    if ("".equals(currentVerisonEntity.getGmVersion())) {
                        lastFirmwareEntity.setIsUpdate(1);
                        lastFirmwareEntity.setMustUpdate(1);
                        isUpdateFlag = 1;
                    } else {
                        int compareVerResult = MGUtils.compareVersion(lastVersion.getGmVersion(), currentVerisonEntity.getGmVersion());
                        //compareVerResult   0代表相等，1代表左边大，-1代表右边大
                        if (compareVerResult == 1) {
                            lastFirmwareEntity.setIsUpdate(1);
                            if (currentFirmware == null) {
                                lastFirmwareEntity.setMustUpdate(1);
                            } else {
                                lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                            }
                            isUpdateFlag = 1;
                        }/*else if (compareVerResult == 0){
                                //后台配置的参数如果是需要强制升级，判断APP上报的固件版本，如果上报的固件版本号等于配置的固件版本号返回需要强制升级字段
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                isUpdateFlag = 0;
                          }*/ else {
                            lastFirmwareEntity.setIsUpdate(0);
                            lastFirmwareEntity.setMustUpdate(0);
                            isUpdateFlag = 0;
                        }
                    }

                }
                if (lastFirmwareEntity != null) {
                    lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());

                    BeanUtils.copyProperties(lastFirmwareEntity, childView);
                }
                view.setGm_data(childView);
            }
        }

        if(!"".equals(currentVerisonEntity.getPdVersion()) && currentVerisonEntity.getPdVersion()!= null){
            // 南芯PD固件
            if (!"".equals(lastVersion.getPdVersion()) && lastVersion.getPdVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("PD", lastVersion.getPdVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("PD", currentVerisonEntity.getPdVersion(), flushFlag);

                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (currentVerisonEntity.getPdVersion() == null) {
                    childView = null;
                } else {
                    if (lastFirmwareEntity == null) {
                        lastFirmwareEntity.setIsUpdate(0);
                        isUpdateFlag = 0;
                    } else {
                        if ("".equals(currentVerisonEntity.getPdVersion())) {
                            lastFirmwareEntity.setIsUpdate(1);
                            isUpdateFlag = 1;
                        } else {
                            int compareVerResult = MGUtils.compareVersion(lastVersion.getPdVersion(), currentVerisonEntity.getPdVersion());
                            //左边大
                            if (compareVerResult == 1) {
                                lastFirmwareEntity.setIsUpdate(1);
                                if (currentFirmware == null) {
                                    lastFirmwareEntity.setMustUpdate(1);
                                } else {
                                    lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                }
                                isUpdateFlag = 1;
                            } else {
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(0);
                                isUpdateFlag = 0;
                            }
                        }
                    }
                    if (lastFirmwareEntity != null) {
                        lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());

                        BeanUtils.copyProperties(lastFirmwareEntity, childView);
                    }
                }
                view.setPd_data(childView);
            }
         }
        //Nordic蓝牙固件， BT
        if(!"".equals(currentVerisonEntity.getBtVersion()) && currentVerisonEntity.getBtVersion()!= null) {
            if (!"".equals(lastVersion.getBtVersion()) && lastVersion.getBtVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("BT", lastVersion.getBtVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("BT", currentVerisonEntity.getBtVersion(), flushFlag);
                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (currentVerisonEntity.getBtVersion() == null) {
                    childView = null;
                } else {
                    if (lastFirmwareEntity == null) {
                        /*  lastFirmwareEntity.setIsUpdate(0);*/
                        isUpdateFlag = 0;
                    } else {
                        if ("".equals(currentVerisonEntity.getBtVersion())) {
                            lastFirmwareEntity.setIsUpdate(1);
                            isUpdateFlag = 1;
                        } else {
                            int compareVerResult = MGUtils.compareVersion(lastVersion.getBtVersion(), currentVerisonEntity.getBtVersion());
                            //左边大
                            if (compareVerResult == 1) {
                                lastFirmwareEntity.setIsUpdate(1);
                                if (currentFirmware == null) {
                                    lastFirmwareEntity.setMustUpdate(1);
                                } else {
                                    lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                }
                                isUpdateFlag = 1;
                            } else {
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(0);
                                isUpdateFlag = 0;
                            }
                        }
                    }
                    if (lastFirmwareEntity != null) {
                        lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());
                        BeanUtils.copyProperties(lastFirmwareEntity, childView);
                    }
                }

                view.setBt_data(childView);
            }
        }

        //PDRS瑞萨 固件
        if(!"".equals(currentVerisonEntity.getPdrsVersion()) && currentVerisonEntity.getPdrsVersion()!= null) {
            if (!"".equals(lastVersion.getPdrsVersion()) && lastVersion.getPdrsVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("PDRS", lastVersion.getPdrsVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("PDRS", currentVerisonEntity.getPdrsVersion(), flushFlag);

                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (currentVerisonEntity.getPdrsVersion() == null) {
                    childView = null;
                } else {
                    if (lastFirmwareEntity == null) {
                        /*  lastFirmwareEntity.setIsUpdate(0);*/
                        isUpdateFlag = 0;
                    } else {
                        if ("".equals(currentVerisonEntity.getPdrsVersion())) {
                            lastFirmwareEntity.setIsUpdate(1);
                            isUpdateFlag = 1;
                        } else {
                            int compareVerResult = MGUtils.compareVersion(lastVersion.getPdrsVersion(), currentVerisonEntity.getPdrsVersion());
                            //左边大
                            if (compareVerResult == 1) {
                                lastFirmwareEntity.setIsUpdate(1);
                                if (currentFirmware == null) {
                                    lastFirmwareEntity.setMustUpdate(1);
                                } else {
                                    lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                }

                                isUpdateFlag = 1;
                            } else {
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(0);
                                isUpdateFlag = 0;
                            }

                        }
                        if (lastFirmwareEntity != null) {
                            lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());
                            BeanUtils.copyProperties(lastFirmwareEntity, childView);
                        }
                    }
                }

                view.setPdrs_data(childView);


            } else {
                view.setPdrs_data(null);
            }
        }

        //泰凌微固件 BTTLW
        if(!"".equals(currentVerisonEntity.getBttlwVersion()) && currentVerisonEntity.getBttlwVersion()!= null) {
            if (!"".equals(lastVersion.getBttlwVersion()) && lastVersion.getBttlwVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("BTTLW", lastVersion.getBttlwVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("BTTLW", currentVerisonEntity.getBttlwVersion(), flushFlag);

                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (currentVerisonEntity.getBttlwVersion() == null) {
                    childView = null;
                } else {
                    if (lastFirmwareEntity == null) {
                        /*  lastFirmwareEntity.setIsUpdate(0);*/
                        isUpdateFlag = 0;
                    } else {
                        if ("".equals(currentVerisonEntity.getBttlwVersion())) {
                            lastFirmwareEntity.setIsUpdate(1);
                            isUpdateFlag = 1;
                        } else {
                            int compareVerResult = MGUtils.compareVersion(lastVersion.getBttlwVersion(), currentVerisonEntity.getBttlwVersion());
                            //左边大
                            if (compareVerResult == 1) {
                                lastFirmwareEntity.setIsUpdate(1);
                                if (currentFirmware == null) {
                                    lastFirmwareEntity.setMustUpdate(1);
                                } else {
                                    lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                }

                                isUpdateFlag = 1;
                            } else {
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(0);
                                isUpdateFlag = 0;
                            }

                        }
                        if (lastFirmwareEntity != null) {
                            lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());
                            BeanUtils.copyProperties(lastFirmwareEntity, childView);
                        }
                    }
                }

                view.setBttlw_data(childView);


            } else {
                view.setBttlw_data(null);
            }
        }
        //GMGM云台国民芯片 固件
        if(!"".equals(currentVerisonEntity.getGmgmVersion()) && currentVerisonEntity.getGmgmVersion()!= null) {
            if (!"".equals(lastVersion.getGmgmVersion()) && lastVersion.getGmgmVersion() != null) {
                //查询当前的固件属性，若为强制升级，mustUpdate即为1，否则 为不强制升级 mustUpdate即为0（说明：最新固件永远不能配置成强制升级，即mustUpdate为0）
                PvMgFirmwareEntity lastFirmwareEntity = getMgFirmwareByType("GMGM", lastVersion.getGmgmVersion(), flushFlag);
                PvMgFirmwareEntity currentFirmware = getMgFirmwareByType("GMGM", currentVerisonEntity.getGmgmVersion(), flushFlag);

                MgItemFirmwareView childView = new MgItemFirmwareView();
                if (currentVerisonEntity.getGmgmVersion() == null) {
                    childView = null;
                } else {
                    if (lastFirmwareEntity == null) {
                        /*  lastFirmwareEntity.setIsUpdate(0);*/
                        isUpdateFlag = 0;
                    } else {
                        if ("".equals(currentVerisonEntity.getGmgmVersion())) {
                            lastFirmwareEntity.setIsUpdate(1);
                            isUpdateFlag = 1;
                        } else {
                            int compareVerResult = MGUtils.compareVersion(lastVersion.getGmgmVersion(), currentVerisonEntity.getGmgmVersion());
                            //左边大
                            if (compareVerResult == 1) {
                                lastFirmwareEntity.setIsUpdate(1);
                                if (currentFirmware == null) {
                                    lastFirmwareEntity.setMustUpdate(1);
                                } else {
                                    lastFirmwareEntity.setMustUpdate(currentFirmware.getMustUpdate());
                                }

                                isUpdateFlag = 1;
                            } else {
                                lastFirmwareEntity.setIsUpdate(0);
                                lastFirmwareEntity.setMustUpdate(0);
                                isUpdateFlag = 0;
                            }

                        }
                        if (lastFirmwareEntity != null) {
                            lastFirmwareEntity.setDownloadPath(ossUrl + lastFirmwareEntity.getDownloadPath());
                            BeanUtils.copyProperties(lastFirmwareEntity, childView);
                        }
                    }
                }

                view.setGmgm_data(childView);


            } else {
                view.setGmgm_data(null);
            }
        }
        view.setIsUpdate(isUpdateFlag);
        return view;
    }

    /**
     * 刷新固件的缓存
     * @param params
     * @return
     */

    @IgnoreAuth
    @RequestMapping(value = "/flushFirmwareCache", produces = "application/json;charset=utf-8;")
    public R flushFirmwareCache(@RequestParam Map<String, String> params) {
        String errMsg = "固件缓存刷新成功";
        boolean firmwareCache_result = pvMgFirmwareVerisonService.flushFirmwareCache();
        if (firmwareCache_result) {
            return R.ok().put("data", errMsg);
        } else {
            return R.error(500, "固件缓存刷新失败");

        }
    }

}
